<template>
    <view class="page">
        <!-- 内容 -->
        <view class="g-tab-content">

			<navigator open-type="navigate" class="g-activity-item" v-for="(item,index) in data" :key="index" :url="'/pages/common/activity_detail?id='+item.id">
				<view class="g-activity-title">
					<text>{{item.title}}</text>
				</view>
				<text class="u-activity-desc">{{item.short_title}}</text>
				<image class="u-activity-img" :src="item.thumb_text" mode="widthFix"></image>
				<view class="u-activity-time">{{item.create_time}}</view>
			</navigator>
            
        </view>
		<view class="m-no-data" v-if="showNodata">
		    <image src="../../static/images/no_data.png" mode="widthFix"></image>
		</view>
		<view class="m-b-loading" v-if="showloading">
		    <image src="../../static/images/loading2.gif"></image>
			<text>加载中</text>
		</view>
    </view>
</template>

<script>
    
    import henglang from '../../common/common.js';
    
    export default {
        data() {
            return {
                data: [], // 活动数据
                page:1,
				total_pages:1,
				showNodata: false,
				showloading :false,
				isGoodType: henglang.isGoodsTpye()
            };
        },
        methods: {
			getList(type) {
				let that = this
				that.showloading = false
				if(that.page <= that.total_pages){
					henglang.get('activity/getList',{page:that.page},false,function(res){
						if(res.data.code == 0){
							if (!res.data.data.length) {
								that.showNodata = true;
								that.data = []
								return false;
							}else{
								that.showNodata = false;
							}
							if(type =='plus'){
								that.data = that.data.concat(res.data.data);
							}else{
								that.data = res.data.data;
								that.total_pages = res.data.total_pages
							}
							
						}
					});
				}
			}
        },
        onShow() {
			if(this.page >= this.total_pages){
				this.page = 1
			}
			this.showloading = true
			this.getList()
        },
		onReachBottom() {
		   this.page += 1
		   this.getList('plus')
		}
    }
</script>

<style>
    image {
        display: block;
    }

    /* 内容 */
    .g-tab-content {
        background: #fafafa;
		padding: 20upx;
    }

    .g-activity-item {
        border-radius: 5px;
        padding: 20upx;
        background: #fff;
        margin-bottom: 20upx;
    }

    .g-activity-title {
        font-size: 30upx;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        line-height: 1;
    }

    .u-activity-desc {
        font-size: 24upx;
        color: #999;
    }

    .u-activity-img {
        width: 100%;
		height: 100%;
        margin-top: 10upx;
    }

    .u-activity-time {
        color: #828080;
        text-align: right;
        margin-top: 5px;
    }

</style>
